package logic

import (
	"context"
	"srv/models/mysql"

	"srv/internal/svc"
	"srv/sesame"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *sesame.GoodsListRequest) (*sesame.GoodsListResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	list, err := g.GetGoodsList()
	if err != nil {
		return nil, err
	}
	var GoodsList []*sesame.GoodsInfo
	for _, goods := range list {
		GoodsList = append(GoodsList, &sesame.GoodsInfo{
			GoodsTitle: goods.GoodsTitle,
			GoodsStock: int64(goods.GoodsStock),
			GoodsCover: goods.GoodsCover,
			GoodsPrice: float32(goods.GoodsPrice),
			GoodsSales: int64(goods.GoodsSales),
		})
	}
	return &sesame.GoodsListResponse{
		List: GoodsList,
	}, nil
}
